package com.yxd.demo.domain;

import java.io.Serializable;

/**
 * @author: yxd
 * @date: 2022/8/1 10:24
 */
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    public static final int SUCCESS = 200;
    public static final int FAIL = 500;
    private int code;
    private String msg;
    private T data;

    public Result() {

    }

    public static <T> Result<T> ok(String msg, T data) {
        return setResult(SUCCESS, msg, data);
    }

    public static <T> Result<T> fail(String msg, T data) {
        return setResult(FAIL, msg, data);
    }

    private static <T> Result<T> setResult(int code, String msg, T data) {
        Result<T> result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
